//
//  MLBLEManager.h
//  MLBLEStatic
//
//  Created by 程杰 on 2023/10/18.
//

#import <Foundation/Foundation.h>
#import "MLBLEModel.h"
NS_ASSUME_NONNULL_BEGIN


// 连接设备回调
typedef void(^BluetoothConnectCompletion)(BOOL success, CBPeripheral *peripheral, NSError *error);
// 断开设备回调
typedef void(^BluetoothDisconnectCompletion)(BOOL success, CBPeripheral *peripheral, NSError *error);
// 数据更新回调
typedef void(^BluetoothDidUpdateValueForCharacteristicCompletion)(CBPeripheral *peripheral,CBCharacteristic *characteristic, NSError *error);

/// 蓝牙信息model
typedef void (^BleScanCompletion )(NSArray<MLBLEModel *> *modes);
//结果返回
typedef void (^BleResultBlock)(MLBleResultInfos *infos);
// 通知是否打开成功
typedef void (^BleNotifyBlock)(BOOL isSuccess);

@interface MLBLEManager : NSObject

@property (nonatomic, copy) BluetoothConnectCompletion connectCompletion;
@property (nonatomic, copy) BluetoothDisconnectCompletion disconnectCompletion;


+ (instancetype)sharedManager;

/// 开始扫描蓝牙
- (void)mlBleScan;
/// 停止扫描并清除数据
- (void)mlBleStopScan;

/// 返回蓝牙列表
- (void)scanPeripheralsCallback:(BleScanCompletion )callBack;

- (void)connectToPeripheral:(CBPeripheral *)peripheral callback:(BluetoothConnectCompletion)callback;
// 通知设置是否成功
- (void)setNotifyisSuccess:(BleNotifyBlock)block;
// 蓝牙通信和回调的方法
- (void)setParamsInfo:(MLBleParamsItem *)params result:(BleResultBlock)resultCallBack;
// 监听断开
- (void)listenBleDisConnect:(BluetoothDisconnectCompletion)disConnectBlock;
// 主动断开
- (void)disconnectFromPeripheral:(CBPeripheral *)peripheral;
// 取消连接
- (void)cancelConnectFromPeripheral:(CBPeripheral *)peripheral;

//- (void)getResultForItem:(MLBleParamsItem *)item  result:(BleResultBlock)resultCallBack;

@end

NS_ASSUME_NONNULL_END
